package bist.believeinstep.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import bist.believeinstep.domain.Article;
import bist.believeinstep.util.Constant.ArticleType;
import bist.believeinstep.util.Constant.State;

/**
 * Ánh xạ dữ liệu trả về với đối tượng Java
 * @author bluheve
 *
 */
public class ArticleMapper implements RowMapper<Article>{

	@Override
	public Article mapRow(ResultSet rs, int rowNum) throws SQLException {
		
		Article article = new Article();
		
		article.setId(rs.getInt("id"));
		article.setCode(rs.getString("code"));
		article.setTitle(rs.getString("title"));
		article.setIntroduction(rs.getString("introduction"));
		article.setContent(rs.getString("content"));
		
		String type = rs.getString("type");	
		article.setType(ArticleType.create(type));
		
		String state = rs.getString("state");
		article.setState(State.create(state));
		
		article.setAvatar(rs.getString("avatar"));
		article.setCreated(rs.getTimestamp("created_date"));
		article.setModified(rs.getTimestamp("modified_date"));
		article.setCreatedBy(rs.getString("created_by"));
		article.setModifiedBy(rs.getString("modified_by"));
		
		return article;
	}

}
